const http = require("http");
const fs = require("fs");
const path = require("path");
const url = require("url");
const mime = require("../mime.json");
const server = http.createServer(function(request,response){

    response.setHeader("content-type","text/html;charset=utf8");
    let pathObj = url.parse(request.url,true) ; 
    // console.log(pathObj);
    if ( request.url == "/" || pathObj.pathname == "/index.html" ){
        // response.write("姓名是"+pathObj.query.name+"年龄是"+pathObj.query.age);
        let data = fs.readFileSync("./index.html");
        response.write(data);
    } else {
        if( request.url !== "/favicon.ico" ){
            let extname = path.extname( request.url );
            let content = mime[extname];
            response.setHeader("content-type",content);
            let data = fs.readFileSync( "./"+request.url );
            response.write(data);
        }
    }
    response.end();
});
server.listen(3333);
console.log(11111111111);